package validator;

import javax.faces.application.FacesMessage;
import javax.faces.component.UIComponent;
import javax.faces.context.FacesContext;
import javax.faces.validator.FacesValidator;
import javax.faces.validator.Validator;
import javax.faces.validator.ValidatorException;

import entity.Measure;

@FacesValidator("measureValidator")
public class MeasureValidator implements Validator {

    @Override
    public void validate(FacesContext context, UIComponent component, Object value) throws ValidatorException {
        Measure m = (Measure) value;
    	
        if (m == null) {
            throw new ValidatorException(new FacesMessage(FacesMessage.SEVERITY_ERROR, null, "selecione uma medida"));
        }else{
            context.addMessage(component.getClientId(), new FacesMessage(FacesMessage.SEVERITY_INFO, null, "ok"));
        }
    }

}
